package com.zprmb.udzt.adapter;

import java.util.List;

import android.content.Context;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zprmb.udzt.BbtApplication;
import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.Info;
import com.zprmb.udzt.util.Regular;

public class InfoAdapter extends BaseAdapter {
	private List<Info> list;
	private Context context;
	

	public InfoAdapter(List<Info> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		Help h=null;
		if(convertView==null){
			h=new Help();
			convertView=LayoutInflater.from(context).inflate(R.layout.info_item, null);
			h.li_activity=(RelativeLayout)convertView.findViewById(R.id.li_activity);
			h.li_new=(LinearLayout)convertView.findViewById(R.id.li_new);
			h.tv_date=(TextView)convertView.findViewById(R.id.tv_date);
			h.tv_description=(TextView)convertView.findViewById(R.id.tv_description);
			h.img_title=(ImageView)convertView.findViewById(R.id.img_title);
			h.tv_new_title=(TextView)convertView.findViewById(R.id.new_title);
			h.tv_title=(TextView)convertView.findViewById(R.id.tv_title);
			h.xian=(View)convertView.findViewById(R.id.v_xian);
			h.rl_al=(RelativeLayout)convertView.findViewById(R.id.rl_al);
			convertView.setTag(h);
			
		}else{
			h=(Help) convertView.getTag();
		}
		
		Log.e("hass", list.get(position).getHasImage()+"");
		if(list.get(position).getTitleImageUrl()==null||list.get(position).getTitleImageUrl().equals("")){
			h.li_activity.setVisibility(View.GONE);
			h.li_new.setVisibility(View.VISIBLE);
			h.tv_new_title.setText(Html.fromHtml(list.get(position).getTitle()));
			h.tv_description.setText(Html.fromHtml(list.get(position).getCmsContent()));
			h.xian.setVisibility(View.VISIBLE);
			
		}else{
			h.li_activity.setVisibility(View.VISIBLE);
			
			h.li_new.setVisibility(View.GONE);
			Log.e("posi", position+"");
			BbtApplication.getInstance().display(list.get(position).getTitleImageUrl(), h.img_title);
			h.tv_title.setText(Html.fromHtml(list.get(position).getTitle()));
			h.xian.setVisibility(View.GONE);
		}
		h.tv_date.setText(Regular.getMilliToDate(list.get(position).getPublicTime()));
//		if(list.get(position).getHasImage().equals("false")){
//			h.li_activity.setVisibility(View.GONE);
//			h.li_new.setVisibility(View.VISIBLE);
//			h.tv_new_title.setText(list.get(position).getTitle());
//			h.tv_description.setText(list.get(position).getTitleDescription());
//		}else{
//			if(position==1){
//				h.li_activity.setVisibility(View.VISIBLE);
//				h.li_new.setVisibility(View.GONE);
//				Log.e("posi", position+"");
//				BbtApplication.getInstance().display(list.get(position).getTitleImageUrl(), h.img_title);
//				h.tv_title.setText(list.get(position).getTitle());
//			}
//			if(position==2){
//				h.li_activity.setVisibility(View.GONE);
//				h.li_new.setVisibility(View.VISIBLE);
//				h.tv_new_title.setText(list.get(position).getTitle());
//				h.tv_description.setText(list.get(position).getTitleDescription());
//				
//			}
//			if(position==3){
//				h.li_activity.setVisibility(View.GONE);
//				h.li_new.setVisibility(View.VISIBLE);
//				h.tv_new_title.setText(list.get(position).getTitle());
//				h.tv_description.setText(list.get(position).getTitleDescription());
//				
//			}
//		}
		
		
		
		
		return convertView;
	}
	private static class Help{
		private TextView tv_title,tv_description,tv_date,tv_new_title;
		private LinearLayout li_new;
		private ImageView img_title;
		private RelativeLayout rl_al,li_activity;
		private View xian;
	}

}
